package com.zyh.jsp.controller;

import com.zyh.jsp.entity.UserEntity;
import com.zyh.jsp.jpa.UserJpa;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserJpa userJpa;

    /**
     * 查询用户列表
     * */
    @RequestMapping("/list")
    public List<UserEntity> list() {
        return userJpa.findAll();
    }

    /**
     * 添加，更新用户
     * */
    @RequestMapping("/update")
    public UserEntity update(UserEntity userEntity){
        return userJpa.save(userEntity);
    }

    /**
     * 删除用户
     * */
    @RequestMapping("/delete")
    public List<UserEntity>  delete(UserEntity userEntity){
        userJpa.delete(userEntity);
        return userJpa.findAll();
    }
}
